package org.nf.ssm.web.controller;

import org.nf.ssm.common.ResultVO;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

/**
 * @author zhu
 * @date 2024-10-12
 */
public class BaseController {

    @InitBinder
    public void dateFormatter(WebDataBinder webDataBinder) {
        webDataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
    }

    public <T> ResultVO<T> success(T data) {
        ResultVO<T> result = new ResultVO();
        result.setCode(HttpStatus.OK.value());
        result.setData(data);
        return result;
    }

    public ResultVO success() {
        ResultVO result = new ResultVO();
        result.setCode(HttpStatus.OK.value());
        return result;
    }
}
